package com.cloud.tsp.controller;

import com.cloud.api.constants.StrVo;
import com.cloud.api.domain.shop.SpuMerchant;
import com.cloud.api.domain.sys.DeptExtend;
import com.cloud.api.domain.sys.DeptExtendQuery;
import com.cloud.api.domain.sys.ReturnAddrRequest;
import com.cloud.core.util.R;
import com.cloud.log.annotation.Log;
import com.cloud.log.enums.BusinessType;
import com.cloud.log.enums.OperatorType;
import com.cloud.mybatis.domain.TableDataInfo;
import com.cloud.tsp.service.IDeptExtendService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import java.io.IOException;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author haohaibo
 * @since 2023-09-13
 */
@RestController
@RequestMapping("/dept-extend")
public class DeptExtendController {

    @Resource
    private IDeptExtendService deptExtendService;

    @Tag(name = "v1.0")
    @Operation(summary = "新增或者修改扩展表(远程)")
    @PostMapping("/insertOrUpdateForDep")
    @Log(title = "组织机构管理-新增或者修改扩展表", businessType = BusinessType.OTHER, operatorType = OperatorType.MANAGE)
    public R insertOrUpdateForDep(@RequestBody @Valid DeptExtend para) throws IOException {
        deptExtendService.saveOrUpdate(para);
        return R.ok();
    }

    @Tag(name = "v1.0")
    @Operation(summary = "导入时批量插入(远程)")
    @PostMapping("/insertBatch")
    @Log(title = "组织机构管理-导入时批量插入", businessType = BusinessType.IMPORT, operatorType = OperatorType.MANAGE)
    public R insertBatch(@RequestBody @Valid List<DeptExtend> para) throws IOException {
        deptExtendService.saveBatch(para);
        return R.ok();
    }


    /*@Tag(name = "v1.0")
    @Operation(summary = "修改扩展表(管理)")
    @PostMapping("/updateDep")
    public R updateDep(@RequestBody @Valid DeptExtend para) throws IOException {
        deptExtendService.updateDep(para);
        return R.ok();
    }*/

    @Tag(name = "v1.0")
    @Operation(summary = "修改退货地址(管理)")
    @PostMapping("/updateReturnAddr")
    @Log(title = "组织机构管理-修改退货地址", businessType = BusinessType.UPDATE, operatorType = OperatorType.MANAGE)
    public R updateReturnAddr(@RequestBody @Valid ReturnAddrRequest para) throws IOException {
        deptExtendService.updateReturnAddr(para);
        return R.ok();
    }

    @Tag(name = "v1.0")
    @Operation(summary = "删除扩展表(远程)")
    @PostMapping("/deleteByIdForDep")
    @Log(title = "组织机构管理-删除扩展表", businessType = BusinessType.DELETE, operatorType = OperatorType.MANAGE)
    public R deleteByIdForDep(@RequestBody @Valid StrVo para) throws IOException {
        deptExtendService.removeById(para.getId());
        return R.ok();
    }

    /*@Tag(name = "v1.0")
    @Operation(summary = "删除扩展表(管理)")
    @PostMapping("/deleteById")
    public R deleteById(@RequestBody @Valid StrVo para) throws IOException {
        deptExtendService.deleteById(para);
        return R.ok();
    }*/

    /*@Tag(name = "v1.0")
    @Operation(summary = "查询部门扩展表(管理)")
    @PostMapping("/getDeptExtendList")
    @Log(title = "组织机构管理-查询部门扩展表", businessType = BusinessType.OTHER, operatorType = OperatorType.MANAGE)
    public TableDataInfo<DeptExtend> selectDeptExtendList(@RequestBody @Valid DeptExtendQuery para) throws IOException {
        return deptExtendService.selectDeptExtendList(para);
    }

    @Tag(name = "v1.0")
    @Operation(summary = "产品部分店铺查询(管理)")
    @PostMapping("/getMerchantsForSpu")
    @Log(title = "组织机构管理-产品部分店铺查询", businessType = BusinessType.OTHER, operatorType = OperatorType.MANAGE)
    public R<SpuMerchant> selectMerchantsForSpu() throws IOException {
        return R.ok(deptExtendService.selectMerchantsForSpu());
    }

    @Tag(name = "v1.0")
    @Operation(summary = "查询部门扩展表详情(管理)")
    @PostMapping("/getDeptExtendDetail")
    @Log(title = "组织机构管理-查询部门扩展表详情", businessType = BusinessType.OTHER, operatorType = OperatorType.MANAGE)
    public R<DeptExtend> selectDeptExtendDetail(@RequestBody @Valid StrVo para) throws IOException {
        return R.ok(deptExtendService.getById(para.getId()));
    }

    @Tag(name = "v1.0")
    @Operation(summary = "商城结算管理（管理）")
    @PostMapping("/getStationList")
    @Log(title = "组织机构管理-商城结算管理", businessType = BusinessType.OTHER, operatorType = OperatorType.MANAGE)
    public TableDataInfo<DeptExtend> selectStationList(@RequestBody @Valid DeptExtendQuery para) throws IOException {
        return deptExtendService.selectStationList(para);
    }*/
}